package com.vrv.im.validate;

import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.vrv.im.domain.UserBean;

public class UserValidate implements Validator {

	@Override
	public boolean supports(Class<?> clazz) {
		return UserBean.class.equals(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {

		UserBean userBean = (UserBean) target;

		if (!StringUtils.hasText(userBean.getToken())) {
			errors.rejectValue("token", "errors.required", "tocken不能为空");
		}
		if (!StringUtils.hasText(userBean.getOpenId())) {
			errors.rejectValue("openId", "errors.required", "openId不能为空");
		}
		if (!StringUtils.hasText(userBean.getName())) {
			errors.rejectValue("name", "errors.required", "用户名称不能为空");
		}
		if (!StringUtils.hasText(userBean.getPhone())) {
			errors.rejectValue("phone", "errors.required", "电话号码不能为空");
		}
	}
}
